import request from '../utils/request'
import store from '@/store'

const getUserChannelListAPI = () => {
  return request({
    url: '/v1_0/user/channels',
    method: 'GET',
    headers: {
      Authorization: `Bearer ${store.state.token}`
    }
  })
}

const getArticleListAPI = ({ channelId, timestamp = Date.now() + '' }) => {
  return request({
    url: '/v1_0/articles',
    method: 'GET',
    params: {
      channel_id: channelId,
      timestamp
    }
  })
}

const articleDislikeAPI = ({ artId }) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'POST',

    data: {
      target: artId
    }
  })
}
const articleReportsAPI = ({ artId, type, remark }) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'POST',

    data: {
      target: artId,
      type,
      remark: type === 0 ? remark : remark || null
    }
  })
}

const getALLChannelListAPI = () => {
  return request({
    url: '/v1_0/channels',
    method: 'GET'
  })
}

const updateUserChannelList = ({ channels }) => {
  return request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels
    }
  })
}
export { getUserChannelListAPI, getArticleListAPI, articleDislikeAPI, articleReportsAPI, getALLChannelListAPI, updateUserChannelList }
